/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utilities;

/**
 *
 * @author HINSKY
 */
import DBHandling.BillHandling;
import Entity.BillDetail;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;
import java.awt.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;

public class BarExample1 {

    
    public static void main(String arg[]) {
        Vector<String> itemName = new Vector<String>();
        Vector<BillDetail> bds = new Vector<BillDetail>();
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        BillHandling bh = new BillHandling();
        try {
            bds = bh.getBillDetailsByName("APPLE");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        
        Date d = Calendar.getInstance().getTime();
        
        for (BillDetail bd : bds) {
            if(bd.getDate().getYear()==d.getYear() && d.getMonth() ==bd.getDate().getMonth())
            {
                dataset.setValue(bd.getQuantity(), "Sales done", String.valueOf(bd.getDate().getDate()));
            }   
        }
        
        JFreeChart chart = ChartFactory.createBarChart("Graph sales-trend for Apple product in August", "Day of month", "Sales done", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        chart.setBackgroundPaint(Color.yellow);
        chart.getTitle().setPaint(Color.blue);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.red);
        ChartFrame frame1 = new ChartFrame("Bar Chart", chart);
        frame1.setVisible(true);
        frame1.setSize(400, 350);
    }
}